vers = {
    "20F5050f":"16.5b1",
    "20D5035i":"16.3b2",
    "20C5032e":"16.2b1",
    "20C65":"16.2",
    "20D47":"16.3",
    "20D67":"16.3.1",
    "20E246":"16.4rc",
    "20E247":"16.4",
    "20E252":"16.4.1",
    "20F66":"16.5",
    "20G5026e":"16.6b1",
    "20G75":"16.6",
    "20G81":"16.6.1",
    "20F75":"16.5.1",
    "20A8372":"16.0",
    "20B110":"16.1.2"
}

devs = {
    "iPhone11,8":"iPhone XR",
    "iPhone11,2":"iPhone XS",
    "iPhone11,4":"iPhone XS Max",
    "iPhone11,6":"iPhone XS Max",
    "iPhone12,8":"iPhone SE 2nd Gen",
    "iPhone12,3":"iPhone 11 Pro",
    "iPhone12,5":"iPhone 11 Pro Max",
    "iPhone12,1":"iPhone 11",
    "iPhone13,3":"iPhone 12 Pro",
    "iPhone13,4":"iPhone 12 Pro Max",
    "iPhone13,2":"iPhone 12",
    "iPhone14,7":"iPhone 14",
    "iPhone14,8":"iPhone 14 Plus",
    "iPhone15,2":"iPhone 14 Pro",
    "iPhone15,3":"iPhone 14 Pro Max",
    "iPhone14,2":"iPhone 13 Pro",
    "iPhone14,3":"iPhone 13 Pro Max",
    "iPhone14,5":"iPhone 13",
    "iPhone14,4":"iPhone 13 Mini",
    "iPhone13,1":"iPhone 12 Mini",
    "iPhone14,6":"iPhone SE 3rd Gen",
}

def extract_ver(line):
    if ".build_version" in line:
        return line.split('"')[1]
#    if ".device_id" in line:
#        print(line.split('"')[1])
    
    return None
    
def extract_dev(line):
    if ".device_id" in line:
        return line.split('"')[1]
    
    return None

def process_file(file_path):
    done_iphones = {}
    done_ipads = {}
    unknown_devs = []
    ipad_lines = []
    lastver = ""
    lastdev = ""
    with open(file_path, 'r') as file:
        for line in file:
            #print(line)
            ver = extract_ver(line)
            if ver is not None:
                lastver = ver
            dev = extract_dev(line)
            if dev is not None:
                lastdev = dev
                if dev in devs:
                    if devs[dev] in done_iphones:
                        if not vers[lastver] in done_iphones[devs[dev]]:
                            done_iphones[devs[dev]].append(vers[lastver])
                    else:
                        done_iphones[devs[dev]] = [vers[lastver]]
                    #print(f"- {devs[dev]} on {vers[lastver]} ({lastver})")
                else:
                    if dev in done_ipads:
                        done_ipads[dev].append(vers[lastver])
                    else:
                        done_ipads[dev] = [vers[lastver]]
#                    if not "iPad" in dev:
#                        if not dev in unknown_devs:
#                            unknown_devs.append(dev)
#                            print(f"unknown device: {dev}")
#                    else:
#                        ipad_lines.append(f"- {dev} on {vers[lastver]} ({lastver})")
    print("### iPhones:")
    for x in done_iphones:
        print(f"- {x}:\\")
        print(", ".join(done_iphones[x]))
    print("### iPads:")
    for x in done_ipads:
        print(f"- {x}:\\")
        print(", ".join(done_ipads[x]))

# Replace 'your_file.txt' with the actual path to your file
process_file('dynamic_info.h')

